<template>
	<view class="wap f16 b89d" v-if="form.id" @click.stop="czClose">
		<u-navbar class="nav" title=" " leftIconColor="#000" leftIconSize="24px" :bgColor="subColor"
			titleStyle="color:#000;font-size:36rpx;" :placeholder="true" safeAreaInsetTop :autoBack="true">
		</u-navbar>
		<view class="tac f20 pt15 top pb80 c0" :style="{background:subColor}">
			{{ form.stateFormat }}
			<view class="f12 mt5" v-if="form.diningType==6">{{form.sourceFormat}}</view>
			<view class="f12 mt5" v-if="form.diningType==4 || form.diningType==5">
				就餐时间：{{form.minutes>=0 && form.minutes!=null ? form.minutes : form.table.minutes}}分钟</view>
		</view>
		<view class="page p10" style="position:relative;top:-40px">
			<view class="p10 card">
				<!-- <view class="p10 bs6">
				<view class="f-c-c">
					<view class="f14 c6">{{form.diningType ==6 ? '取单号' : '流水号'}}</view>
					<view class="f30 wei mt10">
						<text>{{form.pickNo}}</text>
						<text class="ml5 f10 bs4" :style="{padding: '8rpx',background: subColor,color: '#000'}"
							v-if="form.scene==2 && form.diningType == 1">打包</text>
					</view>
				</view>
			</view> -->
				<view class="f-bt f-y-c">
					<view class="flex f-y-c" v-if="form.table && form.table.id">
						<view class="f20 wei ml10">{{form.table.type.name}}{{form.table.name}}</view>
						<view class="f11 c9">（{{form.people}}人）</view>
						<view class="f11 c9" v-if="form.state >0 && form.state <6"><u-icon name="edit-pen" color="#999"
								size="18" @click="clickPeo"></u-icon>
						</view>
					</view>
					<view v-if="form.diningType==6">
						<view class="f20 wei">取单号:{{form.pickNo}}</view>
					</view>
					<view class="flex mr10 f16" :class="{'cf5f':!form.isPay}">
						{{form.orderIndex && form.orderIndex.payStateFormat}}
						<!-- {{form.stateFormat}} -->
					</view>
				</view>
				<view class="f-bt mt10">
					<view class="cf06 f12 ml10">
						<text v-if="form.diningType==4  && form.payType==2 && form.isPay==0" @click="dyyjd">打印预结单</text>
					</view>
					<view class="f-x-e"
						v-if="form.diningType==4 || form.diningType==5 || form.diningType==6">
						<view class="f12 mr10 wei" @click.stop="multipleShow = !multipleShow">操作
						</view>
					</view>
				</view>
			</view>
			<cz :show="multipleShow" tsof="after" :type="form.diningType" :top="130" @op="handInOrder" :v="form"
				mode="multiple" @showStop="showStop"></cz>
			<view class="p10 bf page brs20 mt10">
				<view class="mb10 wei6 c0">商品<text
						class="f12 nowei ml5">{{form.diningType==6 ? form.goods && form.goods.length : form.subGoods && form.subGoods.length}}种共{{form.goodsNum}}件</text>
				</view>
				<block v-if="form.diningType==6">
					<view class="f-bt p-10-0 f12" v-for="(item,index) in form.generalGoods" :key="index">
						<view class="f-g-1">
							<!-- <view class="c0 t-o-e l-h1 f13 flex" @click.stop="namedl(item,index)">
								{{item.name}}
							</view> -->
							<view class="flex f-y-c">
								<image class="mr10 f-g-0 bs5" v-if="item.logo" style="width: 60rpx;height: 60rpx" :src="item.logo" mode="aspectFill" @click="onPreviewTap(item.logo)"></image>
								<view class="c0 t-o-e l-h1 f13 flex" @click.stop="namedl(item,index)">{{item.name}}</view>
							</view>
							<view class="flex f-w f12 c9">
								<view v-if="item.attrData && item.attrData.spec" class="c9 mt5">
									规格：{{item.attrData.spec}}</view>
								<view v-if="item.attrData && item.attrData.attr" class="c9 mt5">
									属性：{{item.attrData.attr}}</view>
								<view v-if="item.attrData && item.attrData.matal" class="c9 mt5">
									加料：{{item.attrData.matal}}</view>
								<view v-if="item.setMealData && item.setMealData.length" class="c9 mt5">
									<view v-for="(cv,ci) in item.setMealData" :key="ci">{{cv.name}}*{{cv.num}}
										<text v-if="cv.attrData && cv.attrData.attr" class="ml10">[{{ cv.attrData.attr }}]</text>
										<text v-if="cv.attrData && cv.attrData.matal" class="ml10">[{{ cv.attrData.matal }}]</text>
									</view>
								</view>
							</view>
						</view>
						<view class="f-g-0 c9 mr15 mumber f-y-c">x{{item.num}}</view>
						<view class="f-g-0 mumber f-y-c">￥{{item.money}}</view>
					</view>
				</block>
				<block v-else>
					<view class="f-bt goods p-r f12" v-for="(item,index) in form.generalGoods" :key="index">
						<view class="c3 wei6 dfa f-g-1">
							<view class="f14 c9" @click.stop="namedl(item,index)">
								<view class="">
									<view class="flex f-y-c">
										<view class="tui" v-if="item.state==8">{{item.discountLabel}}</view>
										<!-- <view class="c0 t-o-e l-h1 f13 flex">
											{{item.name}}
										</view> -->
										<view class="flex f-y-c">
											<image class="mr10 f-g-0 bs5" v-if="item.logo" style="width: 60rpx;height: 60rpx" :src="item.logo" mode="aspectFill" @click="onPreviewTap(item.logo)"></image>
											<view class="c0 t-o-e l-h1 f13 flex">{{item.name}}</view>
										</view>
									</view>
									<view class="flex f-w f12 c9 nowei">
										<view v-if="item.attrData && item.attrData.spec" class="c9 mt5">
											规格：{{item.attrData.spec}}</view>
										<view v-if="item.attrData && item.attrData.attr" class="c9 mt5">
											属性：{{item.attrData.attr}}</view>
										<view v-if="item.attrData && item.attrData.matal" class="c9 mt5">
											加料：{{item.attrData.matal}}</view>
										<view v-if="item.setMealData && item.setMealData.length" class="c9 mt5">
											<view v-for="(cv,ci) in item.setMealData" :key="ci">{{cv.name}}*{{cv.num}}
												<text v-if="cv.attrData && cv.attrData.attr" class="ml10">[{{ cv.attrData.attr }}]</text>
												<text v-if="cv.attrData && cv.attrData.matal" class="ml10">[{{ cv.attrData.matal }}]</text>
											</view>
										</view>
									</view>
								</view>
								<view class="f12 c9 nowei mt5" v-if="item.state==8">退款原因：{{item.reason}}</view>
							</view>
							<cz :show="singleShow" v-if="index==cName" :left="-12" :top="40" :sRight="-25"
								:type="form.diningType" mode="single" :v="item" @op="handsOrder"></cz>
						</view>
						<view class="f-g-0 c9 mr15 mumber f-y-c">x{{item.num}}</view>
						<view class="f-g-0 mumber f-y-c">￥{{item.money}}</view>
					</view>
				</block>
				<view class="mt10" v-if="form.discountsGoods && form.discountsGoods.length">
					<view class="f12 mb5 c9">优惠商品</view>
					<view class="dfa goods" v-for="(item,index) in form.discountsGoods" :key="index">
						<view class="c3 wei6 dfa p-r f12 f-g-1">
							<view class="f14 c9">
								<image class="mr10 f-g-0 bs5" v-if="item.logo" style="width: 60rpx;height: 60rpx" :src="item.logo" mode="aspectFill" @click.stop="onPreviewTap(item.logo)"></image>
								<view @click.stop="nameDisdl(item,index)" class="flex c0 t-o-e l-h1 f13 f-y-c">
									<!-- <view class="uTag mr5 f-c f12 cf" v-if="item.pack">包</view> -->
									{{item.name}}
									<view class="tlabel ml5" :style="{color:'#FD8906',borderColor:'#FD8906'}"
										v-if="item.discountLabel">{{item.discountLabel}}</view>
									<!-- <view class="tlabel ml5" :style="{color:'#FD8906',borderColor:subColor}"
										v-if="item.discountType==2">{{item.discountLabel}}</view>
									<view class="tlabel ml5" :style="{color:'#FD8906',borderColor:subColor}"
										v-if="item.discountType==3">{{item.discountLabel}}</view> -->
								</view>
								<view class="flex f-w f12 c9 nowei">
									<view v-if="item.attrData && item.attrData.spec">[{{ item.attrData.spec }}]</view>
									<view v-if="item.attrData && item.attrData.attr">[{{ item.attrData.attr }}]</view>
									<view v-if="item.attrData && item.attrData.matal">
										{{ item.attrData.matal }}
									</view>
									<view v-if="item.setMealData && item.setMealData.length" class="c9 mt5">
										<view v-for="(cv,ci) in item.setMealData" :key="ci">{{cv.name}}*{{cv.num}}
											<text v-if="cv.attrData && cv.attrData.attr" class="ml10">[{{ cv.attrData.attr }}]</text>
											<text v-if="cv.attrData && cv.attrData.matal" class="ml10">[{{ cv.attrData.matal }}]</text>
										</view>
									</view>
								</view>
							</view>
							<cz :show="singleDisShow" v-if="index==cDisName" :left="-12" :top="40" :sRight="-25"
								:type="form.diningType" mode="singleDis" :v="item" @op="handDisOrder"></cz>
						</view>
						<view class="f-g-0 c9 mr15 mumber f12">x{{item.num}}</view>
						<view class="f-g-0 mumber f-c-e f12">
							<view>￥{{item.money}}</view>
							<view class="f10 c9 t-d-l">￥{{item.sellMoney}}</view>
						</view>
					</view>
				</view>
				<view class="mt10" v-if="form.tableMoney > 0">
					<view class="f-bt">
						<view class="f-g-1 c0 f13 wei">{{form.tableFormat || '服务费'}}</view>
						<view class="f-g-0 c9 mr15 mumber f12">x{{form.tableNum}}</view>
						<view class="f-g-0 mumber f-c-e f12">
							<view>￥{{form.tableMoney}}</view>
						</view>
					</view>
				</view>
				<view class="f-x-e cpjg">
					<view>
						<view class="flex">
							<!-- <view class="f12 c9 f-y-c mr10">共{{form.goodsNum}}份商品</view> -->
							<view class="f20 f-y-c">合计
								<text class="wei f26 ml5 cf5f">￥{{form.money}}</text>
							</view>
						</view>
						<view class="f-x-e f-y-e" v-if="form.sellMoney>form.money"><text
								class="f12 ml5 t-d-l c9">￥{{form.sellMoney}}</text></view>
					</view>
				</view>
			</view>
			<view class="p10 bf mt10 brs20" v-if="form.notes">
				<view class="flex mt10 f14 f-y-t">
					<view class="f-g-0">备注：</view>
					<view>{{form.notes}}</view>
				</view>
			</view>
			<view class="card mt10 f12" style="font-size:30rpx;color:#999"
				v-if="form.discountsPlus && form.discountsPlus.length">
				<view class="mb10 wei6 c0 ">优惠信息</view>
				<block v-for="(v,i) in form.discountsPlus" :key="i">
					<view class="dfbc mb10 f12">
						<text>{{v.activityName}}</text>
						<text class="cf5f">
							<text>-￥{{ v.money }}</text>
							<text v-if="form.diningType == 4 && form.isPay==0 && v.type=='wipeZero'"
								class="f12 crb ml10" @click="cancleWipe('wipeZero')">撤销</text>
						</text>
					</view>
				</block>
				<view class="dfbc mb10 f12">
					<text>优惠合计</text>
					<text>￥{{form.discountMoney || 0}}</text>
				</view>
			</view>
			<view class="card mt10 f12" style="font-size:30rpx;color:#999">
				<view class="f-bt">
					<view class="mb10 wei6 c0">支付信息</view>
					<view class="f12 cf5f">{{ form.payStateFormat }}</view>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>用户实付</text>
					<text>￥{{ form.money }}</text>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<view>支付方式</view>
					<view>
						<view v-if="form.orderIndex && form.orderIndex.orderPay && form.orderIndex.orderPay.length">
							<view class="f-bt mb5 f-y-c" v-for="(v,i) in form.orderIndex.orderPay" :key="i">
								<view class="f-g-1 f12 mr10" v-if="v.payTypeFormat">
									{{v.payTypeFormat}}
									<!-- <text class="f12 mr5 c9">(第{{i+1}}次支付)</text> -->
									</view>
								<view class="f-g-0 f12 cf5f">￥{{v.money}}</view>
							</view>
						</view>
						<view v-else>{{ form.payTypeFormat || form.orderIndex && form.orderIndex.payTypeFormat }}</view>
					</view>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>本单预计收入</text>
					<text>￥{{ form.state==8 ? 0 : form.money }}</text>
				</view>
			</view>
			<view class="card mt10 f12" style="font-size:30rpx;color:#999" v-if="form.state==7 || form.state==8">
				<view class="f-bt">
					<view class="mb10 wei6 c0">退款信息</view>
					<view class="f12 cf5f">{{ form.refundFormat }}</view>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>退款金额</text>
					<text>￥{{ form.state==7 ? form.money : form.refundMoney }}</text>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>申请方</text>
					<text>{{ form.refundNotes }}</text>
				</view>
				<view class="dfbc p-5-0 f12 c0" v-if="form.refundCause">
					<text>退款原因</text>
					<text>{{ form.refundCause }}</text>
				</view>
			</view>
			<view class="p10 bf mt10 brs20">
				<view class="mb10 wei6 c0">订单信息</view>
				<view class="f-g-1">
					<view class="f-bt p-5-0 f12 c0" v-if="form.packagingFormat">
						<view>就餐方式</view>
						<view>{{form.packagingFormat}}</view>
					</view>
					<view class="f-bt p-5-0 f12 c0" v-if="form.openTime">
						<view>开台时间</view>
						<view>{{form.openTime}}</view>
					</view>
					<view class="f-bt p-5-0 f12 c0">
						<view>下单时间</view>
						<view>{{form.created_at}}</view>
					</view>
					<!-- <view class="f-bt p-5-0 f12 c0">
					<view>支付状态</view>
					<view>{{form.orderIndex && form.orderIndex.payStateFormat}}</view>
					<view v-if="form.isPay==1 && form.diningType==4">{{ form.subOrder && form.subOrder[0].orderIndex && form.subOrder[0].orderIndex.payTypeFormat }}</view>
					<view v-else>{{ form.payTypeFormat || form.orderIndex && form.orderIndex.payTypeFormat }}</view>
				</view> -->
					<view class="f-bt p-5-0 f12 c0" v-if="form.sourceFormat">
						<view>下单渠道</view>
						<view>{{form.sourceFormat}}</view>
					</view>
					<view class="f-bt p-5-0 f12 c0">
						<view>下单人</view>
						<view>{{form.admin && form.admin.nickname || '-'}}</view>
					</view>
					<view class="f-bt p-5-0 f12 c0" v-if="form.user">
						<view>关联用户</view>
						<view>{{form.user.nickname}}-{{form.user.mobile}}</view>
					</view>
					<view class="f-bt p-5-0 f12 c0">
						<view>订单编号</view>
						<view>
							<text>{{ form.orderSn }}</text>
							<text :style="{background:subColor}" class="ml5 c0 fz" @click="fz(form.orderSn)">复制</text>
						</view>
					</view>
					<view class="dfbc p-5-0 f12 c0">
						<text>商家备注</text>
						<text>
							{{ form.storeNotes || '-' }}
							<text class="ml5 c0 fz" :style="{background:subColor}" @click="editNotes(form)">编辑</text>
						</text>
					</view>
					<view class="f-bt p-5-0 f12 c0">
						<view>{{form.diningType ==6 ? '取单号' : '流水号'}}</view>
						<view>{{form.pickNo}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="buts dfa tac o-h" v-if="form.state>0 && form.state<6" :style="{borderColor:subColor}">
			<view class="w100 f16 c0 p10 bf" @click="handInOrder('orderPrint')"
				v-if="form.state!=7 && form.state!=2 && !form.addFood && form.state!=4  && form.state!=6">打印订单</view>
			<view class="w100 f16 c0 p10" @click="handInOrder('refunding')" v-if="form.state==7"
				:style="{background:subColor}">同意退款</view>
			<view class="w100 f16 c0 p10 bf" @click="handInOrder('canceling')" v-if="form.state==2">取消订单</view>
			<view class="w100 f16 c0 p10" @click="handInOrder('receiving')" v-if="form.state==2"
				:style="{background:subColor}">立即接单</view>
			<view class="w100 f16 c0 p10" @click="handInOrder('maked')"
				v-if="form.state == 3 && (form.diningType==5 || form.diningType==6)" :style="{background:subColor}">制作完成
			</view>
			<view class="w100 f16 c0 p10 bf" @click="handInOrder('callNum')"
				v-if="form.state == 4 && (form.diningType==6 || form.diningType==5)">叫号
			</view>
			<view class="w100 f16 c0 p10 bf" @click="handInOrder('addOrder')" v-if="form.addFood">继续加菜</view>
			<view class="w100 f16 c0 p10" @click="handInOrder('checkout')"
				v-if="form.state == 3 && form.diningType==4 && form.payType==2" :style="{background:subColor}">
				结账并清台</view>
			<view class="w100 f16 c0 p10" @click="handInOrder('cltable')"
				v-if="form.state == 3 && form.diningType==4 && form.payType==1" :style="{background:subColor}">
				完成并清台</view>
			<view class="w100 f16 c0 p10" @click="handInOrder('completeOrder')"
				v-if="form.state == 4 && (form.diningType==6 || form.diningType==5)" :style="{background:subColor}">
				完成订单</view>
			<!-- 				<view class="w100 f16 cf p10" @click="handInOrder('refundOrder')"
					v-if="form.state > 2 && form.state == 6">退款</view> -->
			<!-- <view class="w100 f16 cf p10" @click="handInOrder('rejecting')" v-if="form.state == 7">拒绝退款</view> -->
		</view>

		<u-modal :show="vipUser" :negativeTop="200" title="会员查询" confirmText="查询" showCancelButton
			confirmColor="'#FD8906'" cancelColor="#000" @confirm="search" @cancel="vipUser = false"
			@close="vipUser = false" :closeOnClickOverlay="true" zoom>
			<view class="slot-content">
				<u--input v-model="phone" type="number" placeholderClass="inni" placeholderStyle="color:#c1c1c1"
					placeholder="请输入手机号" border="none"
					:customStyle="{'width':'100%','flex':1,'background': '#f6f6f6','padding': '10px 15px',}" clearable>
				</u--input>
			</view>
		</u-modal>

		<!-- <u-popup :show="showPay" :round="10" @close="showPay=false" @open="showPay=true" :closeOnClickOverlay="true">
			<view class="p15 c0 f16">
				<view class="dfbc mb10">
					<text>支付金额</text>
					<text class="f14 " :style="{color:subColor}">￥{{form.money}}</text>
				</view>
				<view class="dfbc bb1 p-10-0">
					<u-radio-group v-model="pay.payChannel" placement='column' iconPlacement='right'
						@change="changePay">
						<u-radio :activeColor="subColor" name="authCode" :labelSize="18" :iconSize="14"
							:customStyle="{marginBottom: '50rpx'}">付款码支付</u-radio>
						<u-radio :activeColor="subColor" name="balance" :labelSize="18" :iconSize="14"
							:customStyle="{marginBottom: '50rpx'}">
							<text v-if="payVip && payVip.id">余额支付<text class="f12 c9 ml10"
									:style="{color: subColor}">{{(`余额:${payVip.account.balance}`)}}</text></text>
							<text v-else>余额支付</text>
						</u-radio>
						<u-radio :activeColor="subColor" name="cash" :labelSize="18" :iconSize="14"
							:customStyle="{marginBottom: '50rpx'}">现金支付</u-radio>
					</u-radio-group>
				</view>
				<view>
					<u-button text="立即支付" :color="subColor" @click="goPay"
						:disabled="!pay.payChannel || (pay.payChannel == 'authCode' && !pay.authCode || pay.payChannel == 'balance' && !payVip.id)">
					</u-button>
				</view>
			</view>
		</u-popup> -->

		<u-popup :show="peoShow" :closeOnClickOverlay="true" round="10" @close="peoShow=false" @open="peoShow=true"
			z-index="10100">
			<view class='p-15-10 c0 f16' style="padding-bottom: 215px;">
				<view class="pb10">就餐人数<text class="f12 ml5"
						v-if="form.table">({{form.table.type.name}}{{form.table.name}})</text></view>
				<u-input v-model="value" placeholder="请输入就餐人数" border="none" shape="circle"
					:customStyle="{padding:'20rpx'}" disabled></u-input>
				<cuKeyboard ref="cukeyboard" @change="change" @confirm="confirm" @hide="peoShow=false"></cuKeyboard>
			</view>
		</u-popup>
		<u-modal :show="show" :showCancelButton="true" :closeOnClickOverlay="true" :negativeTop="30" title="商家备注"
			cancelText="取消" :confirmColor="subColor" @cancel="show=false" @close="show=false" @confirm="reasonConfirm">
			<view class="slot-content f-1">
				<u--textarea v-model="reason" placeholder="请输入备注信息"></u--textarea>
			</view>
		</u-modal>
		<giveGoods ref="giveRef" @save="fetchData" :v="form" mode="single"></giveGoods>
		<disGoods ref="disRef" @save="fetchData" :v="form" mode="single"></disGoods>
		<refoundGoods ref="refoundRef" @save="fetchData" :v="form" mode="single"></refoundGoods>
		<pay ref="Pay" :ps="params" :payVip="payVip" @changePay="changePay" @goPay="goPay"></pay>
		<turntable ref="turntableRef" @save="fetchData" :v="form.table"></turntable>
		<member ref="memberRef" @chooseMember="chooseMember" />
		<view class="acshet">
			<u-action-sheet :actions="moreList" @select="selectClick" :closeOnClickOverlay="true"
				:closeOnClickAction="false" @close="moreShow = false" :show="moreShow" cancelText='取消'></u-action-sheet>
		</view>
		<u-modal :show="coinRy" :negativeTop="200" title="任意金额" confirmText="确定" showCancelButton confirmColor="#FD8906"
			cancelColor="#000" @confirm="disconMoney('custom', customMoney)" @cancel="coinRy = false"
			@close="coinRy = false" zoom>
			<view class="slot-content">
				<u--input v-model="customMoney" type="number" placeholderClass="inni" placeholderStyle="color:#c1c1c1"
					placeholder="请输入手动抹零金额" border="none"
					:customStyle="{'width':'100%','flex':1,'background': '#f6f6f6','padding': '10px 15px',}" clearable>
				</u--input>
			</view>
		</u-modal>
		<disOrder ref="disOrderRef" @save="fetchData" :v="form" mode="multiple"></disOrder>
		<freeOf ref="freeOfRef" @save="freeOfOut" :v="form" mode="multiple"></freeOf>
		<u-modal :show="payInfo" :negativeTop="200" title="支付信息" confirmText="确定" showCancelButton
			confirmColor="'#FD8906'" cancelColor="#000" @confirm="payInfo = false" @cancel="payInfo = false"
			@close="payInfo = false" :closeOnClickOverlay="true" zoom>
			<view class="slot-content f-g-1">
				<view class="f-bt mb10" v-for="(v,i) in form.orderIndex.orderPay" :key="i">
					<view class="f-g-1 f14">
						<text class="f12 mr5">第{{i+1}}次</text>
						{{v.PayTypeFormat}}</view>
					<view class="f-g-0 f12 cf5f">￥{{v.money}}</view>
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations,
	} from 'vuex'
	import cz from "./components/czh.vue"
	import giveGoods from "./components/giveGoods.vue"
	import disGoods from "./components/disGoods.vue"
	import refoundGoods from "./components/refoundGoods.vue"
	import cuKeyboard from '@/components/cu-keyboard/cu-keyboard.vue'
	import pay from '@/components/pay/pay.vue'
	import turntable from "./components/turntable.vue"
	import member from '@/components/user/member.vue';
	import disOrder from "./components/disOrder.vue"
	import freeOf from "./components/freeOf.vue"
	import {
		fuzhi,
		callTel,
	} from "@/common/handutil.js";
	export default {
		components: {
			cz,
			giveGoods,
			disGoods,
			refoundGoods,
			cuKeyboard,
			pay,
			turntable,
			member,
			disOrder,
			freeOf,
		},
		data() {
			return {
				subColor: uni.getStorageSync('subject_color'),
				show: false,
				selectVip: {},
				payVip: {},
				form: {},
				params: {
					packaging: 0,
					userId: 0,
					notes: '',
					money: '',
					payType: 0,
					authCode: '',
				},
				carList: {},
				orderList: [],
				vipUser: false,
				phone: '',
				showPay: false,
				pay: {
					payType: 0,
					authCode: 0,
					payUserId: 0,
					costomPayId: 0,
				},
				orderInfo: {},
				multipleShow: false,
				cName: 0,
				cDisName: 0,
				singleShow: false,
				singleDisShow: false,
				peoShow: false,
				value: '',
				id: '',
				cForm: {},
				reason: '',
				moreShow: false,
				coinRy: false,
				customMoney: '',
				moreList: [{
						name: '抹分',
						value: 'F'
					},
					{
						name: '抹角',
						value: 'J'
					},
					{
						name: '抹元',
						value: 'Y'
					},
					{
						name: '任意金额',
						value: 'R'
					}
				],
				payInfo:false,
			}
		},
		async onLoad(options) {
			if (options && options.id) {
				await this.fetchData(options.id)
				this.isload = true
				this.id = options.id
			}
			this.getReasonConfig()
		},
		computed: {
			...mapState({
				storeId: state => state.storeId,
			}),
		},
		onShow() {
			if (this.isload && this.id) {
				this.fetchData(this.id)
			}
		},
		methods: {
			...mapMutations(["setConfig"]),
			async fetchData(id) {
				let {
					data
				} = await this.beg.request({
					url: `${this.api.inStoreOrder}/${id}`,
					data: {
						storeId: this.storeId
					},
				})
				this.form = data
			},
			async getReasonConfig() {
				let {
					data
				} = await this.beg.request({
					url: this.api.config,
					data: {
						ident: 'reasonConfig'
					}
				})
				this.setConfig({
					name: 'reasonConfig',
					data,
				})
			},
			namedl(v, i) {
				if (this.form.payType == 1 || this.form.state == 6) return
				this.cName = i
				this.cForm = v
				this.singleShow = !this.singleShow
			},
			nameDisdl(v, i) {
				if (this.form.payType == 1 || this.form.state == 6) return
				this.cDisName = i
				this.cForm = v
				this.singleDisShow = !this.singleDisShow
			},
			async clickPeo() {
				this.peoShow = true
				this.value = this.form.people
				this.$nextTick(() => this.$refs.cukeyboard.open())
			},
			change(e) {
				this.value = e;
			},
			async confirm(e) {
				if (+this.value) {
					let {
						msg
					} = await this.beg.request({
						url: `${this.api.cPeople}/${this.form.table.id}`,
						method: 'POST',
						data: {
							people: +this.value
						}
					})
					uni.$u.toast(msg);
					this.fetchData(this.id)
					this.peoShow = false
				} else {
					this.peoShow = false
					uni.$u.toast('请输入正确就餐人数！');
				}
			},
			async handInOrder(type,scene) {
				let n = '',
					a = ''
				if (type == 'checkout') {
					this.params.money = this.form.money
					this.$refs['Pay'].open(this.params)
					return
				} else if (type == 'addOrder') {
					return uni.redirectTo({
						url: `/pages/order/orderMeal/index?id=${this.form.table.id}`
					})
				} else if (type == 'give') {
					this.multipleShow = false
					return uni.navigateTo({
						url: `/pages/order/orders/give?orderSn=${this.form.orderSn}&type=${type}`
					})
				} else if (type == 'backFood') {
					this.multipleShow = false
					return uni.navigateTo({
						url: `/pages/order/orders/give?orderSn=${this.form.orderSn}&type=${type}`
					})
				} else if (type == 'urgeUp') {
					this.multipleShow = false
					return uni.navigateTo({
						url: `/pages/order/orders/give?orderSn=${this.form.orderSn}&type=${type}`
					})
				} else if (type == 'turntable') {
					return this.$refs['turntableRef'].open(type)
				} else if (type == 'parallel') {
					return this.$refs['turntableRef'].open(type)
				} else if (type == 'coin') {
					this.multipleShow = false
					return this.moreShow = true
				} else if (type == 'discountOrder') {
					this.multipleShow = false
					return this.$refs['disOrderRef'].open(this.form)
				} else if (type == 'cancleWipe') {
					this.multipleShow = false
					return this.cancleWipe('manualDiscountd')
				} else if (type == 'freeOf') {
					this.multipleShow = false
					return this.$refs['freeOfRef'].open(this.form)
				}
				switch (type) {
					case 'orderPrint':
						n = "你确定打印该订单吗";
						a = 'printOrder';
						break;
					case 'canceling':
						n = "你确定取消订单吗";
						a = 'inOClose';
						break;
					case 'refusal':
						n = "你确定拒单吗";
						a = 'inOClose';
						break;
					case 'receiving':
						n = "你确定立即接单吗";
						a = 'inStoreReceived';
						break;
					case 'refunding':
						n = "你确定同意退款吗";
						a = 'inRefund';
						break
					case 'refundOrder':
						n = "你确定退款吗";
						a = 'inRefund';
						break
					case 'maked':
						n = "你确定制作完成吗";
						a = 'inStoreMaked';
						break;
					case 'completeOrder':
						n = "你确定完成订单吗";
						a = 'inStoreComplete';
						break;
					case 'callNum':
						n = "你确定叫号吗";
						a = 'callNum';
						break;
					case 'rejecting':
						n = "你确定拒绝退款吗";
						a = 'inReject';
						break;
					case 'cx':
						n = "你确定撤销吗";
						a = 'backTb';
						break;
					case 'cltable':
						n = "你确定清台吗";
						a = 'inStoreComplete';
						break;
					case 'orderPrints':
						n = "你确定打印该订单吗";
						a = 'printOrders';
						break;
				}
				console.log(a, n)
				if (a == 'callNum') {
					let {
						msg
					} = await this.beg.request({
						url: `${this.api[a]}/${this.form.id}`,
						method: "POST",
						data: {
							scene: this.form.scene
						}
					})
					this.fetchData(this.form.orderSn)
					uni.$u.toast(msg)
				} else if (a == 'cltable') {
					let {
						msg
					} = await this.beg.request({
						url: `${this.api[a]}/${this.form.id}`,
						method: "POST",
						data: {
							scene: this.form.scene
						}
					})
					this.fetchData(this.form.orderSn)
					uni.$u.toast(msg)
				} else if (a == 'printOrder') {
					uni.showModal({
						title: '温馨提示',
						content: n,
						success: async (res) => {
							if (res.confirm) {
								let {
									msg
								} = await this.beg.request({
									url: `${this.api[a]}/${a=='backTb' ? this.form.table.id : this.form.id}`,
									method: "POST",
									data: {
										scene: 3,
										order_type: 7
									}
								})
								this.multipleShow = false
								this.fetchData(this.form.orderSn)
								uni.$u.toast(msg)
							}
						}
					});
				} else if(a == 'printOrders'){
					let {
						msg
					} = await this.beg.request({
						url: `${this.api.printOrder}/${this.form.id}`,
						method: "POST",
						data: {scene,}
					})
					this.multipleShow = false
					this.fetchData(this.form.orderSn)
					uni.$u.toast(msg)
				}
				else {
					uni.showModal({
						title: '温馨提示',
						content: n,
						success: async (res) => {
							if (res.confirm) {
								let {
									msg
								} = await this.beg.request({
									url: `${this.api[a]}/${a=='backTb' ? this.form.table.id : this.form.id}`,
									method: "POST",
									data: {
										scene: this.form.scene
									}
								})
								this.multipleShow = false
								this.fetchData(this.form.orderSn)
								uni.$u.toast(msg)
							}
						}
					});
				}
			},
			selectClick(e) {
				this.moreShow = false
				if (e.value == 'R') {
					this.coinRy = true
				} else {
					this.disconMoney(e.value)
				}
			},
			async disconMoney(type, discount) {
				let {
					data
				} = await this.beg.request({
					url: `${this.api.orderWipeZero}/${this.form.orderSn}`,
					method: 'POST',
					data: {
						diningType: this.form.diningType,
						storeId: this.form.storeId,
						tableId: this.form.id,
						type,
						discount,
					}
				})
				this.coinRy = false
				this.moreShow = false
				this.fetchData(this.form.orderSn)
			},
			async cancleWipe(type) {
				let {
					data
				} = await this.beg.request({
					url: `${this.api.orderCancelDiscount}/${this.form.orderSn}`,
					method: 'POST',
					data: {
						diningType: this.form.diningType,
						storeId: this.form.storeId,
						tableId: this.form.id,
						type,
					}
				})
				this.fetchData(this.form.orderSn)
			},
			freeOfOut() {
				uni.switchTab({
					url: `/pages/index/index`
				})
			},
			async handsOrder(type) {
				let n = '',
					a = ''
				if (type == 'give') {
					this.$refs['giveRef'].open(this.cForm)
				} else if (type == 'discount') {
					this.$refs['disRef'].open(this.cForm)
				} else if (type == 'backFood') {
					this.$refs['refoundRef'].open(this.cForm)
				} else if (type == 'cancelbackFood') {
					this.handDisOrder('cancelbackFood')
				} else if (type == 'urgeUp') {
					uni.showModal({
						title: '温馨提示',
						content: '确定催起吗',
						success: async (res) => {
							let {
								msg
							} = await this.beg.request({
								url: `${this.api[a]}/${this.form.orderSn}`,
								method: "POST",
								data: {
									goods: [{
										id: this.cForm.id,
										num: this.cForm.num
									}],
									type: 'urgeUp',
									storeId: this.form.storeId,
									tableId: this.form.tableId,
									diningType: this.form.diningType,
								}
							})
							this.singleDisShow = false
							this.fetchData(this.form.orderSn)
						}
					});
				}
				this.singleShow = false
			},
			async handDisOrder(type) {
				let n = '',
					a = ''
				 if (type == 'hyGive') {
					this.$refs['giveRef'].open(this.cForm)
					this.singleDisShow = false
					return
				}else if (type == 'hyBackFood') {
					this.$refs['refoundRef'].open(this.cForm)
					this.singleDisShow = false
					return
				}
				switch (type) {
					case 'backGive':
						n = "你确定取消赠菜吗";
						a = 'giveOrder';
						break;
					case 'backDis':
						n = "你确定取消打折吗";
						a = 'giveOrder';
						break;
					case 'backSub':
						n = "你确定取消立减吗";
						a = 'giveOrder';
						break;
					case 'cancelbackFood':
						n = "你确定取消退菜吗";
						a = 'giveOrder';
						break;
				}
				uni.showModal({
					title: '温馨提示',
					content: n,
					success: async (res) => {
						if (res.confirm) {
							let {
								msg
							} = await this.beg.request({
								url: `${this.api[a]}/${this.form.orderSn}`,
								method: "POST",
								data: {
									goods: [{
										id: this.cForm.id,
										num: this.cForm.num
									}],
									type: 'back',
									storeId: this.form.storeId,
									tableId: this.form.tableId,
									diningType: this.form.diningType,
								}
							})
							this.singleDisShow = false
							this.fetchData(this.form.orderSn)
						}
					}
				});
			},
			async dyyjd() {
				let {
					msg
				} = await this.beg.request({
					url: `${this.api.printOrder}/${this.form.id}`,
					method: "POST",
					data: {
						scene: 6,
						orderSn: this.form.orderSn,
						tableId: this.form.tableId
					}
				})
				this.fetchData(this.form.orderSn)
				uni.$u.toast(msg)
			},
			async goPay() {
				if (this.form.diningType == 4) {
					let {
						data,
						msg
					} = await this.beg.request({
						url: `${this.api.inPay}/${this.form.prentOrderSn || this.form.orderSn}`,
						method: 'POST',
						data: this.pay
					})
					uni.showToast({
						title: msg,
						icon: 'none',
					});
					if (data && data) {
						// #ifdef MP-WEIXIN
						uni.reLaunch({
							url: `/pages/order/orders/index`
						})
						// #endif
						// #ifndef MP-WEIXIN
						uni.switchTab({
							url: `/pages/index/index`
						})
						// #endif
					}
				} else {
					this.fastOrder()
				}
			},
			async fastOrder() {
				let {
					data
				} = await this.beg.request({
					url: this.api.inOrder,
					method: 'POST',
					data: this.pay
				})
				this.orderInfo = data
				if (data && data.orderSn) {
					// #ifdef MP-WEIXIN
					uni.reLaunch({
						url: `/pages/order/orders/index`
					})
					// #endif
					// #ifndef MP-WEIXIN
					uni.switchTab({
						url: `/pages/index/index`
					})
					// #endif
				}
			},
			vip() {
				this.selectVip = {}
				this.params.userId = ''
				this.checkOut()
			},
			changePay(e) {
				if (e == 'authCode') {
					this.vipUser = false
					this.pay.payType = 'authCode'
					var that = this
					uni.scanCode({
						onlyFromCamera: true,
						success: async function(res) {
							uni.showLoading({
								title: 'loading...'
							})
							if (res.result) {
								that.pay.authCode = res.result
								if (that.form.diningType == 4) {
									that.goPay()
								} else {
									that.fastOrder()
								}
							} else {
								uni.hideLoading()
							}
						},
					});
				} else if (e == 'balance') {
					this.pay.payType = 'balance'
					this.vipUser = true
					this.vipUserType = 2
				} else if (e == 'cash') {
					this.vipUser = false
					this.pay.payType = 'cash'
				}else{
					this.pay.costomPayId = e
					this.pay.payType = 'costomPay'
					this.params.payType = 'costomPay'
				}
			},
			async search() {
				const reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
				if (this.phone) {
					this.vipUser = false
					uni.showLoading({
						title: 'loading...'
					})
					let {
						data
					} = await this.beg.request({
						url: this.api.cMember,
						data: {
							mobile: this.phone
						},
					})
					if (data && data.list.length) {
						if (data.list.length > 1) {
							this.$refs['memberRef'].open(data.list)
						} else {
							if (this.vipUserType == 2) {
								this.payVip = data.list[0]
								this.pay.payUserId = data.list[0].id
								console.log(this.payVip)
							} else {
								this.selectVip = data.list[0]
								this.params.userId = data.list[0].id
								this.checkOut()
								console.log(this.selectVip)
							}
						}
					} else {
						uni.$u.toast('暂未查到用户信息');
					}
					uni.hideLoading()
				} else {
					uni.$u.toast('请输入正确的手机号');
				}
			},
			chooseMember(e) {
				if (this.vipUserType == 2) {
					this.payVip = e
					this.pay.payUserId = e.id
					console.log(this.payVip)
				} else {
					this.selectVip = e
					this.params.userId = e.id
					this.checkOut()
					console.log(this.selectVip)
				}
			},
			fz(n) {
				fuzhi(n)
			},
			czClose() {
				this.multipleShow = false
				this.singleShow = false
				this.singleDisShow = false
			},
			showStop() {
				this.multipleShow = true
			},
			editNotes(v) {
				if (v.storeNotes && v.storeNotes != null) this.reason = v.storeNotes
				this.show = true
			},
			async reasonConfirm() {
				let {
					msg
				} = await this.beg.request({
					url: `${this.api.inNotes}/${this.form.id}`,
					method: "POST",
					data: {
						notes: this.reason
					},
				})
				this.fetchData(this.form.orderSn)
				uni.$u.toast(msg)
				this.show = false
			},
			seePay(){
				if(this.form.orderIndex && this.form.orderIndex.orderPay){
					this.payInfo = true
				}
			},
			onPreviewTap(i) {
				let ci = []
				ci.push(i)
			    uni.previewImage({
			        current: 0,
			        urls:ci
			    })
			},
		}
	}
</script>

<style lang="scss" scoped>
	.wap {
		padding-bottom: 160rpx;
		overflow: auto;
	}

	// .page {
	// 	margin: 20rpx 30rpx 0 30rpx;
	// }

	.ddxx {
		margin: 10rpx 30rpx;
	}

	.w65 {
		width: 65%;
	}


	.goods {
		padding: 15rpx 0;
	}

	.tlabel {
		padding: 2rpx 4rpx;
		font-size: 20rpx;
		font-weight: normal;
		color: #fff;
		border-radius: 6rpx;
		margin-right: 10rpx;
		border: 2rpx solid #f5f5f5;
	}

	.tui {
		padding: 2rpx 4rpx;
		font-size: 20rpx;
		font-weight: normal;
		color: #fff;
		border-radius: 6rpx;
		margin-right: 10rpx;
		background: #3E77B9;
	}

	.cpjg {
		border-top: 2rpx solid #f5f5f5;
		margin-top: 30rpx;
		padding: 20rpx 0;
	}

	.buts {
		position: fixed;
		bottom: 40rpx;
		left: 50%;
		transform: translateX(-50%);
		width: 90%;
		height: 80rpx;
		border-radius: 50rpx;
		border: 2rpx solid #fff;
	}

	.brs20 {
		border-radius: 20rpx;
	}

	.mumber {
		width: 100rpx;
	}

	.fz {
		padding: 6rpx;
		border-radius: 4rpx;
	}

	/deep/ .u-button__text {
		font-size: 17px !important;
	}

	.uTag {
		background: #1c9945;
		width: 36rpx;
		height: 36rpx;
		border-radius: 6rpx;
	}
</style>